package yhp.dao.impl;

import com.alibaba.druid.pool.DruidDataSource;
import yhp.bean.Student;
import yhp.dao.StudentDao;
import yhp.util.Dbutils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//实体类+Dao+Impl == 类名
public class StudentDaoImpl extends Dbutils implements StudentDao {
    @Override
    public List<Student> lookall() throws SQLException {
        ArrayList<Student> list = null;
        try {
            String sql = "SELECT * FROM student";
            ResultSet query = query(sql);
            list = new ArrayList<>();
            while (query.next()){
                Student student = new Student();
                student.setStuid(query.getInt("stuid"));
                student.setName(query.getString("name"));
                student.setAge(query.getInt("age"));
                student.setSex(query.getInt("sex"));
                list.add(student);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeall();
        }
        return list;
    }
}
